<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/base.jsp"%>
<%@ include file="/module/taglibs.jsp"%>
<%@ include file="/module/nocache.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>学生奖学金申请管理</title>
<%@ include file="/module/js.jsp"%>
<script type="text/javascript">
$(document).ready(
		function() {
			$('#dg').datagrid({
				onClickRow: function (rowIndex, rowData) {
	                $(this).datagrid('unselectRow', rowIndex);
	         },
// 			 onSortColumn :function(sort,order){
// 			   var _sort=sort;
// 			   var _order=order;
// 			   var options=$('#dg').datagrid('getPager').data("pagination").options;
// 			   var page=options.pageNumber;
// 			   var pageSize=options.pageSize;
// 			   window.setTimeout(function(){
// 				   $.post("${basePath}/scholarship/scholarshipStudentList",{orderFlag:_order,orderField:_sort,
// 					   xnd: $('#xnd').val()
// 					   },function(data){
// 							  $('#dg').datagrid("loadData",data); 
// 						   });
// 				 },100);  
// 			   },
			   rowStyler: function(index,row){
			   },
			   onLoadSuccess: function(data){//加载完毕后获取所有的checkbox遍历
	                 if (data.rows.length > 0) {
	                    //循环判断操作为新增的不能选择
	                    var checkbox = $("input[type='checkbox']");
	                    for (var i = 0; i < data.rows.length; i++) {
	                        //根据operate让某些行不可选
	                        if (data.rows[i].states != 0) {
		                      $(checkbox.get(i+1)).remove();
	                        }
	                    }
	                }
				},
			});
			
			 $('#easyui-ck').click(function() {
				    var data = $("#dg").datagrid("getSelections");
                 for (var i = 0; i < data.length; i++) {
                     //根据states让某些行不可选
                     if (data[i].states != 0) {
	                     $('#dg').datagrid('unselectRow',i);//选择该行 
	                     $("#easyui-ck").attr('checked','checked'); 
                     }
                 }
				}); 
			
			//查询
			$('#btnQuery').click(function() {
			  $('#dg').datagrid('load',{
				  xnd: $('#xnd').val()
			  });
			});
			//新增
			$('#btnAdd').click(function() {
			  document.scholarshipForm.action = "${basePath}/scholarship/addScholarshipStudentForward";
			  document.scholarshipForm.submit();
			});
			//删除
			$('#btnDelete').click(function() {
			    $("#idList").val("");
			    var count = 0;		
				var idList = new Array();
			    var sels = $("#dg").datagrid("getSelections");
			    for(var i in sels){
			       if(sels[i].states!=2&&sels[i].states!=3){
			    	   idList.push(sels[i].sqid);
						count++;   
			       }
			    }
			  if (count == 0) {
				layer.alert("你至少选择一条删除记录信息", {icon: 3});
				return false;
				}else{
					  layer.confirm("你是否删除当前选中数据信息", {icon: 3, title:'提示',skin:'layer-ext-moon'}, function(index){
						    $("#idList").val(idList);
						    document.scholarshipForm.action = "${basePath}/scholarship/removeStudentScholarship";
							document.scholarshipForm.submit();
					  },function(index){
							layer.close(index);
					  });
				}
			});
// 			$('#btnExport').on('click', function(){
// 				   layer.confirm("您确定要导出吗?", {icon: 3, title:'提示',skin:'layer-ext-moon'}, function(index){
// 					   var rows = $("#dg").datagrid("getRows");
// 					   var bodyData = JSON.stringify(rows);  //转成json字符串
// 					    $("#bodyData").val(JSON.stringify(rows));
// 							document.semesterForm.action = "${basePath}/semesterSummary/exportRecommendStudent";
// 							document.semesterForm.submit();
//             		 });
// 				});
		});

//取消单击选选中的功能
function clickRow(index, row) {
   var checkedRows = $("#dg").datagrid("getChecked");
   var isNotCheckedFlag = true;
   if(row){
       for(var i=0;i<checkedRows.length;i++){
           if(row.uid == checkedRows[i].uid ){
               isNotCheckedFlag = false;
               break;
           }
       }
   }
   if(isNotCheckedFlag){
       $(this).datagrid('unselectRow', index);
   } else {
       $(this).datagrid('selectRow', index);
   }
}

function formaterLink(value, row, index) {
    return "<a href='${basePath}/scholarship/modiftyStudentScholarshipForward?sqid=" + row.sqid+"'>" + value + "</a>";
}
//操作
function formaterOperate(value, row, index) {
   if(row.jxjdj==1&&row.states==3){  //审核通过
	   return "<input type=\"button\"  autocomplete=\"off\"  value=\"奖学金登记\" class=\"inputButton\" onclick=\"javascript:studentScholarshipRegister("+row.sqid+");\"/>";
   }else{
	  return null;
   } 
}
//登记
function studentScholarshipRegister(sqid){
  document.scholarshipForm.action = "${basePath}/scholarship/studentScholarshipRegister?sqid="+sqid;
  document.scholarshipForm.submit();	
}


</script>


</head>
<body>
	<form action="#" name="scholarshipForm" id="scholarshipForm" method="post">
	  <input type="hidden" id="idList" name="idList" value=""/>
		<table cellpadding="1" cellspacing="1" border="0">
			<tr>
				<td><input type="button" id="btnQuery" autocomplete="off"  value="查询"
					class="inputButton" /></td>
				<td><input type="button" id="btnAdd" autocomplete="off"  value="添 加"
					class="inputButton" /></td>
				<td><input type="button" id="btnDelete" autocomplete="off"  value="删除"
					 class="inputButton"/></td>
			</tr>
		</table>
		<table cellpadding="1" cellspacing="1">
			<tr>
				<td>学年：</td>
				<td>
				<select id="xnd" name="xnd" class="selectList2">
				 <option value="">全部</option>
				 <c:forEach items="${yearList}" var="y">
				 <option value="${y.xnd}">${y.xnd}</option>
				 </c:forEach>
				</select>
			</td>
			</tr>
		</table>
		<br/>
     <table id="dg"  style="width:100%;"
		data-options="pagination:true,collapsible:true,url:'${basePath}/scholarship/scholarshipStudentList',method:'post',remoteSort:true,striped:true">
		<thead>
			<tr>
				<th data-options="field:'sqid',checkbox:true,width:100,align:'center'"></th>
				<th data-options="field:'xnd',sortable:true,nowrap:true,width:200,align:'center',formatter:formaterLink">学年</th>
				<th data-options="field:'jxjdj',sortable:true,nowrap:true,width:200,align:'center'">奖学金等级</th>
				<th data-options="field:'states',sortable:true,nowrap:true,width:200,align:'center',formatter:formaterState">状态</th>
				<th data-options="field:'sqly',sortable:true,nowrap:true,width:200,align:'center'">申请理由</th>
				<th data-options="field:'createtime',nowrap:true,width:300,align:'center',formatter:formatDate">提交时间</th>
				<th data-options="field:'operate',nowrap:true,width:300,align:'center',formatter:formaterOperate">操作</th>
			</tr>
		</thead>
	</table>
		<script type="text/javascript">
			 if("${msg}"!=""){
			       layer.alert("${msg}", {icon: 6});
			  } 
			 compareListValue(document.getElementById('xnd'),'${xnd}');
			 
		</script>
	</form>
</body>
</html>
